package lab03;


import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TopPassword {
    private static final String SQL = "SELECT password  ,count(*)  from db_csdn.csdn GROUP BY password ORDER BY count(*) desc limit 10";

    public static void main(String[] args) throws SQLException, IOException {
        Connection connection = DBCPDatasource.getConnection();

        PreparedStatement preparedStatement = connection.prepareStatement(SQL);


        //
        long starTime = System.currentTimeMillis();
        ResultSet resultSet = preparedStatement.executeQuery(SQL);
        System.out.println("密码"+"\t\t\t\t\t"+"数量");

        while (resultSet.next()){

            String password = resultSet.getString("password");
            String count = resultSet.getString("count(*)");
            System.out.println(password+"\t\t\t\t"+count);

        }

        long endTime = System.currentTimeMillis();
        resultSet.close();
        preparedStatement.close();
        connection.close();
        System.out.println("共耗时"+(endTime-starTime)+"ms.");
    }
}

/*
         密码					数量
        123456789				2782
        12345678				2550
        11111111				1014
        00000000				434
        123123123				210
        1234567890				198
        88888888				182
        987654321				88
        111111111				84
        password				74
        共耗时384ms.
        */
